package net.wanho.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import net.wanho.common.Constants;
import net.wanho.po.Product;
import net.wanho.service.ProductService;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author：汤小洋
 * Date：2025-07-03 14:49
 * Description：<描述>
 */
@RestController
@RequestMapping("/product")
@RequiredArgsConstructor
public class ProductController {

    private final ProductService productService;

    /**
     * 添加和修改
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody Product product){
        productService.saveProduct(product);
        return AjaxResult.success();
    }

    /**
     * 查询所有
     */
    @GetMapping
    public AjaxResult findAll(){
        List<Product> list = productService.list();
        return AjaxResult.success(list);
    }

    @GetMapping("/query")
    public AjaxResult query(Product product){
        List<Product> list = productService.find(product);
        return AjaxResult.success(list);
    }

    @GetMapping("/page")
    public AjaxResult page(@RequestParam(required = false, defaultValue = "1") int pageNum,
                           @RequestParam(required = false, defaultValue = "3") int pageSize,
                           Product product){
        Page<Product> page = productService.findPage(pageNum, pageSize, product);
        return AjaxResult.success(page);
    }

}
